namespace eval system {

}

proc system::exec_return_value {args} {
    set status 0
    if {[catch {uplevel ::exec $args} results]} {
       if {[lindex $::errorCode 0] == "CHILDSTATUS"} {
          set status [lindex $::errorCode 2]
       } else {
          # Some kind of unexpected failure
       }
    }
    return $status
}

proc system::kill {pid {signal 9}} {
    ::exec kill -$signal $pid
}

proc system::exec_with_timeout { timeout args } {
     set pid [uplevel eval ::exec $args &]
     puts "pid=$pid"
     after $timeout kill 9 $pid
     while {[exec_return_value ps -p $pid] == 0} {
         after 3000
         puts "$pid is running ..."
	 update
     }
     return
}

